package com.orange.score.service;

import android.os.AsyncTask;
import android.util.Log;
import com.orange.common.android.activity.PPActivity;
import com.orange.score.constants.LanguageType;
import com.orange.score.model.config.ConfigManager;
import com.orange.score.model.league.LeagueManager;
import com.orange.score.model.repository.RepositoryManager;
import com.orange.score.network.RepositoryNetworkRequest;
import com.orange.score.network.ResultCodeType;
import com.orange.score.utils.FileService;

public class RepositoryService
{
  private static final String TAG = RepositoryService.class.getName();
  private LeagueManager leagueManager;
  private RepositoryManager repositoryManager = new RepositoryManager();

  public RepositoryService()
  {
    this.leagueManager = new LeagueManager();
  }

  public LeagueManager getLeagueManager()
  {
    return this.leagueManager;
  }

  public RepositoryManager getRepositoryManager()
  {
    return this.repositoryManager;
  }

  public void loadGroupInfo(PPActivity paramPPActivity, RepositoryServiceCallBack paramRepositoryServiceCallBack, String paramString1, String paramString2)
  {
    LoadGroupInfoTask localLoadGroupInfoTask = new LoadGroupInfoTask(this, paramRepositoryServiceCallBack);
    String[] arrayOfString = new String[2];
    arrayOfString[0] = paramString1;
    arrayOfString[1] = paramString2;
    localLoadGroupInfoTask.execute(arrayOfString);
  }

  public void loadRepository(PPActivity paramPPActivity, RepositoryServiceCallBack paramRepositoryServiceCallBack)
  {
    LoadRepositoryTask localLoadRepositoryTask = new LoadRepositoryTask(this, paramPPActivity, paramRepositoryServiceCallBack);
    String[] arrayOfString = new String[1];
    arrayOfString[0] = "";
    localLoadRepositoryTask.execute(arrayOfString);
  }

  public void loadRoundInfo(PPActivity paramPPActivity, RepositoryServiceCallBack paramRepositoryServiceCallBack, String paramString1, String paramString2)
  {
    LoadRoundInfoTask localLoadRoundInfoTask = new LoadRoundInfoTask(this, paramPPActivity, paramRepositoryServiceCallBack);
    String[] arrayOfString = new String[2];
    arrayOfString[0] = paramString1;
    arrayOfString[1] = paramString2;
    localLoadRoundInfoTask.execute(arrayOfString);
  }

  private class LoadGroupInfoTask extends AsyncTask<String, Void, String[]>
  {
    RepositoryServiceCallBack callback;

    public LoadGroupInfoTask(, RepositoryServiceCallBack paramRepositoryServiceCallBack)
    {
      this.callback = paramRepositoryServiceCallBack;
    }

    protected String[] doInBackground()
    {
      return RepositoryNetworkRequest.getRepositoryGroupInfo(paramArrayOfString[0], paramArrayOfString[1]);
    }

    protected void onPostExecute()
    {
      if (paramArrayOfString == null)
        Log.w(RepositoryService.access$0(), "get groupInfo from network null");
      while (true)
      {
        while (true)
        {
          return;
          if (paramArrayOfString.length >= 3)
            break;
          Log.w(RepositoryService.access$0(), "get groupInfo data but length not enough, length = " + paramArrayOfString.length);
        }
        String str = "";
        if (paramArrayOfString.length >= 3)
          str = paramArrayOfString[0];
        String[] arrayOfString = str.split("\\!");
        RepositoryService.access$1(this.this$0).updateGroupInfoFromStringList(arrayOfString);
        this.callback.loadGroupInfoFinish(ResultCodeType.SUCCESS);
      }
    }
  }

  private class LoadRepositoryTask extends AsyncTask<String, Void, String[]>
  {
    PPActivity activity;
    RepositoryServiceCallBack callback;

    public LoadRepositoryTask(, PPActivity paramPPActivity, RepositoryServiceCallBack paramRepositoryServiceCallBack)
    {
      this.callback = paramRepositoryServiceCallBack;
      this.activity = paramPPActivity;
    }

    protected String[] doInBackground()
    {
      String[] arrayOfString4;
      int k;
      int l;
      String[] arrayOfString1 = new String[3];
      String str1 = FileService.currentDate();
      FileService localFileService = new FileService(this.activity);
      try
      {
        String str2 = localFileService.read("repository.txt");
        Log.d(RepositoryService.access$0(), "Get repository info from repository.txt");
        arrayOfString4 = str2.split("\\$\\$");
        int j = Integer.parseInt(arrayOfString4[0]);
        String str3 = arrayOfString4[1];
        k = Integer.parseInt(str1);
        l = Integer.parseInt(str3);
        if (j != ConfigManager.getLanguage().intValue())
          throw new Exception();
      }
      catch (Exception localException)
      {
        StringBuilder localStringBuilder;
        int i;
        String[] arrayOfString3;
        Log.d(RepositoryService.access$0(), "Get repository info from network");
        String[] arrayOfString2 = RepositoryNetworkRequest.getAllRepository(ConfigManager.getLanguage());
        if (arrayOfString2 == null)
          arrayOfString3 = null;
        while (true)
        {
          return arrayOfString3;
          if (k - l < 168)
          {
            int i1 = 0;
            while (true)
            {
              while (i1 >= arrayOfString1.length)
                arrayOfString3 = arrayOfString1;
              arrayOfString1[i1] = arrayOfString4[(i1 + 2)];
              ++i1;
            }
          }
          throw new Exception();
          localStringBuilder = new StringBuilder();
          localStringBuilder.append(ConfigManager.getLanguage().intValue()).append("$$");
          localStringBuilder.append(str1);
          i = 0;
          if (i < arrayOfString2.length)
            break;
          localFileService.save("repository.txt", localStringBuilder.toString());
          arrayOfString3 = arrayOfString2;
        }
        localStringBuilder.append("$$").append(arrayOfString2[i]);
        ++i;
      }
    }

    protected void onPostExecute()
    {
      this.activity.hideDialog();
      if (paramArrayOfString == null)
        Log.w(RepositoryService.access$0(), "get repository from network null");
      while (true)
      {
        while (true)
        {
          return;
          if (paramArrayOfString.length >= 3)
            break;
          Log.w(RepositoryService.access$0(), "get repository data but length not enough, length = " + paramArrayOfString.length);
        }
        String str1 = "";
        String str2 = "";
        String str3 = "";
        if (paramArrayOfString.length >= 3)
        {
          str1 = paramArrayOfString[0];
          str2 = paramArrayOfString[1];
          str3 = paramArrayOfString[2];
        }
        String[] arrayOfString1 = str1.split("\\!");
        RepositoryService.access$1(this.this$0).updateContinentDataFromStringList(arrayOfString1);
        String[] arrayOfString2 = str2.split("\\!");
        RepositoryService.access$1(this.this$0).updateCountryDataFromStringList(arrayOfString2);
        String[] arrayOfString3 = str3.split("\\!");
        RepositoryService.access$2(this.this$0).updateDataFromStringList(arrayOfString3, 3);
        this.callback.loadAllRepositoryFinish(ResultCodeType.SUCCESS);
      }
    }

    protected void onPreExecute()
    {
      this.activity.showProgressDialog("", "加载数据中");
    }
  }

  private class LoadRoundInfoTask extends AsyncTask<String, Void, String[]>
  {
    PPActivity activity;
    RepositoryServiceCallBack callback;

    public LoadRoundInfoTask(, PPActivity paramPPActivity, RepositoryServiceCallBack paramRepositoryServiceCallBack)
    {
      this.activity = paramPPActivity;
      this.callback = paramRepositoryServiceCallBack;
    }

    protected String[] doInBackground()
    {
      return RepositoryNetworkRequest.getRepositoryRoundInfo(paramArrayOfString[0], paramArrayOfString[1]);
    }

    protected void onPostExecute()
    {
      if (paramArrayOfString == null)
        Log.w(RepositoryService.access$0(), "get LoadRoundInfo from network null");
      while (true)
      {
        while (true)
        {
          return;
          if (paramArrayOfString.length >= 2)
            break;
          Log.w(RepositoryService.access$0(), "get LoadRoundInfo data but length not enough, length = " + paramArrayOfString.length);
        }
        String str1 = "";
        String str2 = "";
        if (paramArrayOfString.length >= 2)
        {
          str2 = paramArrayOfString[0];
          str1 = paramArrayOfString[1];
        }
        String str3 = str1.split("\\!")[0].split("\\^")[0];
        RepositoryService.access$2(this.this$0).updateLeagueRound(str2, str3);
        this.callback.loadRoundInfoFinish(ResultCodeType.SUCCESS);
      }
    }

    protected void onPreExecute()
    {
    }
  }
}